<?php
/**
 * Created by PhpStorm.
 * User: mingzhongshui
 * Date: 2020/3/31
 * Time: 21:09
 */

namespace App\Repositories\Wx;

use App\Repositories\Repository;
use Carbon\Carbon;

/**
 * Class WxNoticeRepository
 * @package App\Repositories\Wx
 */
class WxNoticeRepository extends Repository
{

    /**
     * @return string
     */
    public function model()
    {
        return \App\Models\Wx\WxNotice::class;
    }

    /**
     * 状态
     */
    const STATUS_UN_SEND = 0; // 未发送
    const STATUS_IS_SEND = 1; // 已发送

    /**
     * 类型
     */
    const TYPE_INTEGRAL_IMPORT = 3; // 积分导入

    /**
     * @return mixed
     */
    public function getUnPushRecord()
    {
        return $this->model->where('status', self::STATUS_UN_SEND)->where('type', self::TYPE_INTEGRAL_IMPORT)->get();
    }

    /**
     * @param $id
     * @return mixed
     */
    public function updateSend($id)
    {
        return $this->model
                    ->where('id', $id)
                    ->update([
                        'status' => self::STATUS_IS_SEND,
                        'send_datetime' => (new Carbon())->toDateTimeString()
                    ]);
    }

}
